Page({

  /**
   * 页面的初始数据
   */
  data: {
    oddAddress: '',//补充信息
    address: '',//百度地图suggestion取到的结果
    person: '',//联系人
    personPhone: '',//联系电话
    gps_lat: 0,
    gps_lon: 0,
    privnce: null,
    city: null,
    area: null,
    whichPage: 1,//1：表示选择发货地 2：表示选择收货地

    // < province city area >的Bean
    //   province: { name: "", code: "" },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      whichPage: options.whichPage
    });
  },

  /**
   * 点击选择行政区域
   */
  click_selectArea: function (e) {
    wx.navigateTo({
      url: '../select_place/select_place',
    });
  },

  /**
   * 点击编辑详细的地址信息
   */
  click_toEditAddress: function (e) {
    var that = this;
    wx.navigateTo({
      url: '../fill_address_detail/fill_address_detail?suggestionCity=' + that.data.city.name,
    });
  },

  /**
   * 确定按钮
   */
  click_confirm: function (e) {
    var that = this;
    var province = that.data.province;
    var city = that.data.city;
    var area = that.data.area;
    var address = that.data.address;
    var person = that.data.person;
    var personPhone = that.data.personPhone;
    if (null == province ||
      null == city ||
      null == area ||
      '' === address ||
      '' === person ||
      '' === personPhone) {
      wx.showToast({
        title: '请完善信息',
        image: '../../../images/warn.png',
        duration: 2000
      });
    } else {
      var pages = getCurrentPages();
      var prePage = pages[pages.length - 2];
      if (1 == that.data.whichPage) {
        //将发货信息写入到上一个页面
        prePage.setData({
          fromAddress: {
            province: province,
            city: city,
            area: area,
            address: address,
            oddAddress: that.data.oddAddress,
            gps_lat: that.data.gps_lat,
            gps_lon: that.data.gps_lon,
          },
          fromPerson: {
            person: person,
            phone: personPhone,
          },
        });
      } else {
        //将收货信息写入到上一个页面
        prePage.setData({
          toAddress: {
            province: province,
            city: city,
            area: area,
            address: address,
            oddAddress: that.data.oddAddress,
            gps_lat: that.data.gps_lat,
            gps_lon: that.data.gps_lon,
          },
          toPerson: {
            person: person,
            phone: personPhone,
          },
        });
      }
      wx.navigateBack();
    }
  },

  /**
   * 补充信息的输入
   */
  input_editOddAddress: function (e) {
    this.setData({
      oddAddress: e.detail.value
    });
  },

  /**
   * 姓名的输入
   */
  input_personName: function (e) {
    this.setData({
      person: e.detail.value
    });
  },

  /**
   * 电话号码的输入
   */
  input_personPhone: function (e) {
    this.setData({
      personPhone: e.detail.value
    });
  },
})